﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Delegates_And_Events
{
    class TestMethod
    {
        delegate void UniversalDelegate(int param);

        public static void ResolveFirstTask(int n)
        {
            double result = 0;

            for (int i = 0; i < n; i++)
            {
                double calculaitons = 1 / Math.Pow(2, i);
                result += calculaitons;
            }

            Console.WriteLine("first task: {0}", result);
        }

        public static void ResolveSecondTask(int n)
        {
            double result = 0;

            for (int i = 1; i <= n; i++)
            {
                double factorielResult = 1;

                for (int f = 1; f <= i; f++)
                {
                    factorielResult *= f;
                }
                
                double calculaitons = 1 / factorielResult;
                //Console.WriteLine("i->{0}, factorielResult -> {1}, calc -> {2}", i, factorielResult, calculaitons);
                result += calculaitons;
            }
            Console.WriteLine("second task: {0}", result);
        }

        public static void ResolveThirdTask(int n)
        {
            double result = 0;

            for (int i = 0; i < n; i++)
            {
                double calculaitons = 1 / Math.Pow(2, i);
                if (i > 0)
                {
                    calculaitons *= Math.Pow(-1, i + 1);
                }
                result += calculaitons ;
            }

            Console.WriteLine("third task: {0}", result);
        }

        static void Main(string[] args)
        {

            UniversalDelegate d = new UniversalDelegate(ResolveFirstTask);
            d += ResolveSecondTask;
            d += ResolveThirdTask;
            d(3);
        }
    }
}
